class Coordinate{
  private int x;
  private int y;
  
  public Coordinate(int x, int y){
    this.x = x;
    this.y = y;
  }
  
  int getX(){
    return x;
  }
  
  int getY(){
    return y;
  }
  
  void incX(){
    x+=1;
  }
  
  void decX(){
    x-=1;
  }
  
  void decY(){
    x-=1;
  }

  
  void incY(){
    y+=1;
  }
  
  void setX(int newX){
    x = newX;
  }
  
  void setY(){
  }
}

class Geometry{

  Coordinate coord;  
  
  boolean moveRight = true; //false => left
  
  Geometry(Coordinate coord){
    this.coord = coord;
  }
  
  Coordinate getCoord(){
    return coord;
  }
  
  void moveLeft(){}
  
  void moveRight(){}
  
  void moveUp(){}
  
  void moveDown(){}
  
  void display(){}
  
  void bounce(){}

}

class Rectangle extends Geometry{

  private int w;
  private int h;
  
  public Rectangle(Coordinate coord, int w, int h){
    super(coord);
    this.w = w;
    this.h = h;
  }
  
  void display(){
    rect(coord.getX(), coord.getY(), w, h);
  }
  
  void moveRight(){
    coord.incX();
  }
  
  void bounce(){
    if(moveRight){
      coord.incX();
      if(coord.getX()+w >=width){
         moveRight = false;   
      }  
    }else{
      coord.decX();
      if(coord.getX()<=0){
        moveRight = true;
      }
    }
    
  }

  
}

class Line{
  Coordinate begin;
  Coordinate end;
  
  Line(Coordinate begin, Coordinate end){
    this.begin = begin;
    this.end = end;
  }
  
  void display(){
    
  }
  
}

class Triangle extends Geometry{
  Line[] lines;
  
  public Triangle (Coordinate coord){
    super(coord);
  } 
  
  void display(){
   //???
  }
}

Rectangle myRectangle = new Rectangle(new Coordinate(20, 20), 40, 80);

void setup() {
  size(200, 200);
  background(255);
  println("width? = " + width);
  //myRectangle.display();
}

void draw(){
  background(255);
  myRectangle.bounce();
  myRectangle.display();
}



